package service;

import mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Customer;
import pojo.QueryVo;
import utils.Page;

import java.util.List;

@Service

public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public Page<Customer> getCustomerByQueryVo(QueryVo queryVo) {

        //计算分页查询从那条开始
        queryVo.setStart((queryVo.getPage() - 1) * queryVo.getRows());

        //查询总记录数
        Integer count = customerMapper.getCountByQueryVo(queryVo);
        //查询每页数据列表
        List<Customer> list = customerMapper.getCustomerByQueryVo(queryVo);

        //包装分页数据
        Page<Customer> page = new Page<Customer>(count, queryVo.getPage(), queryVo.getRows(), list);

        return page;
    }

    @Override
    public Customer getCustomerById(Integer id) {
        return customerMapper.getCustomerById(id);
    }

    @Override
    public void updateCustomer(Customer customer) {
        customerMapper.updateCustomer(customer);
    }

    @Override
    public void deleteCustomer(Integer id) {
        customerMapper.deleteCustomer(id);
    }
}

